import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import qiankun from "vite-plugin-qiankun";
import { resolve } from "path";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    qiankun("sub-app", {
      // 子应用名称
      useDevMode: true, // 开发模式
    }),
  ],
  base: "/",
  server: {
    port: 3000,
    cors: true,
    origin: "http://localhost:3000",
    headers: {
      "Access-Control-Allow-Origin": "*",
    },
  },
  resolve: {
    alias: {
      "@": resolve(__dirname, "src"),
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "@/styles/variables.scss" as *;`,
      },
    },
  },
  build: {
    target: "esnext",
    lib: {
      entry: resolve(__dirname, "src/main.js"),
      name: "micro-web-app",
      formats: ["umd"],
      fileName: "micro-web-app",
    },
    rollupOptions: {
      output: {
        globals: {
          vue: "Vue",
        },
      },
    },
  },
});
